package org.squirrel.modules.bigscreen.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.squirrel.common.api.vo.Result;
import org.squirrel.common.system.base.controller.SquirrelController;
import org.squirrel.modules.bigscreen.dto.DataSetParamDto;
import org.squirrel.modules.bigscreen.entity.DataSetParam;
import org.squirrel.modules.bigscreen.param.DataSetParamValidationParam;
import org.squirrel.modules.bigscreen.service.DataSetParamService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 数据集动态参数管理
 * 
 * @author think
 *
 */
@Slf4j
@RestController
@Api(tags = "数据集动态参数管理")
@RequestMapping("/dataSetParam")
public class DataSetParamController extends SquirrelController< DataSetParam, DataSetParamService> {
    @Autowired
    private DataSetParamService dataSetParamService;

    /**
     * 测试 查询参数是否正确
     * @param param
     * @return
     */
    @ApiOperation(value = "测试查询参数是否正确", notes = "测试查询参数是否正确")
    @PostMapping("/verification")
    public Result<?> verification(@Validated @RequestBody DataSetParamValidationParam param) {
    	try {
	        DataSetParamDto dto = new DataSetParamDto();
	        dto.setSampleItem(param.getSampleItem());
	        dto.setValidationRules(param.getValidationRules());
	        Object obj = dataSetParamService.verification(dto);
	        return Result.OK("测试查询参数是否正确", obj);
    	}catch(Exception e) {
    		log.error("测试查询参数是否正确异常", e);
			return Result.error("测试查询参数是否正确失败,原因:" + e.getMessage());
    	}
    }
}
